<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "product".
 *
 * @property integer $id
 * @property string $name
 * @property integer $cat_id
 * @property string $description
 * @property string $image
 * @property integer $price
 * @property string $create_date
 * @property string $update_date
 * @property integer $active
 */
class Product extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public $file;
    public static function tableName()
    {
        return 'product';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name','description','price'],'required'],
            [['cat_id', 'price', 'active'], 'integer'],
            [['create_date', 'update_date'], 'safe'],
            [['file'],'image'],
            [['name'], 'string', 'max' => 45],
            [['description'], 'string', 'max' => 255],
            [['image'], 'string', 'max' => 60]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'cat_id' => 'Category',
            'description' => 'Description',
            'image' => 'Image',
            'price' => 'Price',
            'create_date' => 'Create Date',
            'update_date' => 'Update Date',
            'active' => 'Active',
        ];
    }
    public static function getImage($id){
        $model=Product::findOne($id);
        return $model['image'];
    }
    public static function getactive($active){
        if($active==1){
            return "Actived";
        }elseif($active==0){
            return "Not Active";
        }
    }
}
